package models;

import java.sql.*;

/* 
 * this package will contain all the things that has to do with accessing the database; getting and setting.
 */

public class MainModels {

	
	public static void main(String[] args) { // Testing the connection to MySQL.

        Connection con = null;
        Statement st = null;
        ResultSet rs = null;

        String url = "jdbc:mysql://localhost:3306/tasy_trade";
        String user = "root";
        String password = "1234";

        try {
            con = DriverManager.getConnection(url, user, password);
            st = con.createStatement();
            rs = st.executeQuery("SELECT * FROM tasy_trade.Product");

            System.out.println("id  Name");
            while(rs.next()) { // For every row in the result set
            	System.out.print(rs.getString("id") + "   "); // Print the id and
                System.out.println(rs.getString("Name")); // print the name
            }

        } catch (SQLException ex) {

        } finally { // Forces the program to always do this before it exits.
            try {
                if (rs != null) {
                    rs.close(); // Close the result set connection.
                }
                if (st != null) {
                    st.close(); // Close the statement connection.
                }
                if (con != null) {
                    con.close(); // Close the DB connection.
                }

            } catch (SQLException ex) {
            	
            }
        }
        
    }


}
